﻿using Common.Communal;
using ERP.Domain.Scheduling;
using MediatR;
using Scheduling.Api.Read.Application.Command.ShiftCommand;
using SqlSugar;

namespace Scheduling.Api.Read.Application.CommandHandlers.ShiftHandler
{
    public class ShiftCreateCommandHandler : IRequestHandler<ShiftCreateCommand, ApiResult<List<Shift>>>
    {
        public ShiftCreateCommandHandler(ISqlSugarClient sqlSugar)
        {
            SqlSugar = sqlSugar;
        }

        public ISqlSugarClient SqlSugar { get; }

        public Task<ApiResult<List<Shift>>> Handle(ShiftCreateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Shift>> result = new ApiResult<List<Shift>>
            {
                Code = EnumCode.Ok,
                Message = "班次显示成功"
            };

            var query = SqlSugar.Queryable<Shift>().Where(s => s.IsDelete == false);
            var list = query.OrderBy(s => s.ShiftId).ToList();
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
